package com.kycxika.app.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by caro on 16/6/30.
 *
 * useage:
 * 当使用别人的账户进行登录时,获取的值都是 "";
 * 没注册成功过就不保存任何信息
 * 注册成功后方保存,不然用户名value == "";
 */
public class PreferenceHelper extends PreferencesCommHelper{


    /**
     * 获得当前账户的昵称
     *
     * @param mContext
     * @return
     */
    public static String getCurUserNick(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"Nick", "");
        return s;
    }


    /**
     * 当前账户的昵称
     *
     * @param mContext
     * @return
     */
    public static void saveCurUserNick(Context mContext, String userNick) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"Nick", userNick).commit();

    }

    /**
     * 当前账户的token
     *
     * @param mContext
     * @return
     */
    public static void saveToken(Context mContext, String userNick) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"token", userNick).commit();

    }

    /**
     * 获得当前账户token
     *
     * @param mContext
     * @return
     */
    public static String getToken(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"token", "");
        return s;
    }

    /**
     * 当前账户的token
     *
     * @param mContext
     * @return
     */
    public static void saveRandom(Context mContext, String userNick) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"random", userNick).commit();

    }

    /**
     * 获得当前账户token
     *
     * @param mContext
     * @return
     */
    public static String getRandom(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"random", "");
        return s;
    }


    /**
     * 获得当前账户的名字(如真实姓名)
     *
     * @param mContext
     * @return
     */
    public static String getCurUserName(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"name", "");
        return s;
    }


    /**
     * 保存当前账户的名字
     *
     * @param mContext
     * @return
     */
    public static void saveCurUserName(Context mContext, String username) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"name", username).commit();

    }

    /**
     * 获得当前账户的签名
     *
     * @param mContext
     * @return
     */
    public static String getCurUserSignature(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"Signature", "");
        return s;
    }


    /**
     * 保存当前账户的签名
     *
     * @param mContext
     * @return
     */
    public static void saveCurUserSignature(Context mContext, String signature) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"Signature", signature).commit();

    }

    /**
     * 获得当前账户的性别
     *
     * @param mContext
     * @return
     */
    public static int getCurUserSex(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        int sex = sp.getInt(userCount+"_"+"Sex", -1);
        return sex;
    }


    /**
     * 保存当前账户的性别
     *
     * @param mContext
     * @return
     */
    public static void saveCurUserSex(Context mContext, int sex) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putInt(userCount+"_"+"Sex", sex).commit();

    }

    /**
     * 获得当前账户的名字(如真实姓名)
     *
     * @param mContext
     * @return
     */
    public static String getLoginToken(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"name", "");
        return s;
    }


    /**
     * 保存当前账户的名字
     *
     * @param mContext
     * @return
     */
    public static void SaveLoginToken(Context mContext, String username) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"name", username).commit();

    }


    /**
     * 获得当前账户的名字(如真实姓名)
     *
     * @param mContext
     * @return
     */
    public static String getDownPath(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        String s = sp.getString(userCount+"_"+"DownPath", "");
        return s;
    }


    /**
     * 保存当前账户的名字
     *
     * @param mContext
     * @return
     */
    public static void SaveDownPath(Context mContext, String username) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putString(userCount+"_"+"DownPath", username).commit();

    }

    public static void saveCurUserID(Context mContext, int uid) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        sp.edit().putInt(userCount+"_"+"UUID", uid).commit();

    }

    public static int getCurUserID(Context mContext) {
        SharedPreferences sp = (SharedPreferences) mContext.getSharedPreferences(AppInfoUtil.getAppName(mContext), 0);
        String userCount = getCurUserCount(mContext);
        int s = sp.getInt(userCount+"_"+"UUID", 0);
        return s;
    }
}
